package siga.visao_financeiro;

import java.sql.SQLException;
import java.text.ParseException;
import siga.banco.conexao;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import siga.visao.index;
import siga.visao.verErros;
import siga.visao_busca.*;

public class movContasPagarNovo extends javax.swing.JDialog {
    List LRcaixa = new ArrayList();
    public boolean finaliza=false;
    
    public movContasPagarNovo(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        GrupoAcao = new javax.swing.ButtonGroup();
        GrupoRateio = new javax.swing.ButtonGroup();
        jpPrincNovo = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfFornecedor = new javax.swing.JTextField();
        jbNovoForn = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jtfTipo = new javax.swing.JComboBox();
        jtfNrDoc = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtfHistorico = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtfDtVenc = new javax.swing.JFormattedTextField();
        jtfDtPag = new javax.swing.JFormattedTextField();
        jtfValorPago = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jtfPlanoCod = new javax.swing.JTextField();
        jtfPlanoDesc = new javax.swing.JTextField();
        jbBuscar1 = new javax.swing.JButton();
        jtfCaixa = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jtfValorBruto = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jtfValorJuro = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jtfCentroCod = new javax.swing.JTextField();
        jtfCentroDesc = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jbBuscar2 = new javax.swing.JButton();
        jbBuscar3 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jtfAcaoPagar = new javax.swing.JRadioButton();
        jtfAcaoProv = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jrAuto = new javax.swing.JRadioButton();
        jrManual = new javax.swing.JRadioButton();
        jtVlManual = new javax.swing.JTextField();
        jbNovo = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jbSalvar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtPgto = new javax.swing.JTable();
        jbRemover = new javax.swing.JButton();
        jbInserir = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jtfParcela = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Novo Lançamento de Pagamento");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jpPrincNovo.setName("jpPrincNovo"); // NOI18N
        jpPrincNovo.setLayout(null);

        jLabel1.setText("Pessoa/Fornecedor");
        jLabel1.setName("jLabel1"); // NOI18N
        jpPrincNovo.add(jLabel1);
        jLabel1.setBounds(10, 10, 130, 14);

        jtfFornecedor.setEditable(false);
        jtfFornecedor.setName("jtfFornecedor"); // NOI18N
        jpPrincNovo.add(jtfFornecedor);
        jtfFornecedor.setBounds(10, 30, 460, 20);

        jbNovoForn.setFont(new java.awt.Font("Dialog", 0, 10));
        jbNovoForn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/Business_People_16x16.png"))); // NOI18N
        jbNovoForn.setText("Novo");
        jbNovoForn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbNovoForn.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jbNovoForn.setName("jbNovoForn"); // NOI18N
        jbNovoForn.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbNovoForn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbNovoForn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNovoFornActionPerformed(evt);
            }
        });
        jpPrincNovo.add(jbNovoForn);
        jbNovoForn.setBounds(530, 10, 40, 40);

        jLabel2.setText("Tipo do Título");
        jLabel2.setName("jLabel2"); // NOI18N
        jpPrincNovo.add(jLabel2);
        jLabel2.setBounds(10, 70, 100, 14);

        jLabel3.setText("Número Doc.");
        jLabel3.setName("jLabel3"); // NOI18N
        jpPrincNovo.add(jLabel3);
        jLabel3.setBounds(420, 70, 80, 14);

        jtfTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nota Fiscal", "Cupom Fiscal", "Fatura de Compras", "Memorando", "Pedido", "Recibo", "Extrato Bancário", "Outros" }));
        jtfTipo.setName("jtfTipo"); // NOI18N
        jpPrincNovo.add(jtfTipo);
        jtfTipo.setBounds(10, 90, 160, 20);

        jtfNrDoc.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jtfNrDoc.setText("0");
        jtfNrDoc.setName("jtfNrDoc"); // NOI18N
        jpPrincNovo.add(jtfNrDoc);
        jtfNrDoc.setBounds(420, 90, 80, 20);

        jLabel4.setText("Histórico");
        jLabel4.setName("jLabel4"); // NOI18N
        jpPrincNovo.add(jLabel4);
        jLabel4.setBounds(10, 130, 70, 14);

        jtfHistorico.setName("jtfHistorico"); // NOI18N
        jpPrincNovo.add(jtfHistorico);
        jtfHistorico.setBounds(10, 150, 560, 20);

        jLabel5.setText("Data de Pgto");
        jLabel5.setName("jLabel5"); // NOI18N
        jpPrincNovo.add(jLabel5);
        jLabel5.setBounds(110, 180, 80, 14);

        jLabel6.setText("Data de Venc.");
        jLabel6.setName("jLabel6"); // NOI18N
        jpPrincNovo.add(jLabel6);
        jLabel6.setBounds(10, 180, 90, 14);

        jLabel7.setText("Valor Pago");
        jLabel7.setName("jLabel7"); // NOI18N
        jpPrincNovo.add(jLabel7);
        jLabel7.setBounds(440, 180, 90, 14);

        try {
            jtfDtVenc.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jtfDtVenc.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jtfDtVenc.setName("jtfDtVenc"); // NOI18N
        jpPrincNovo.add(jtfDtVenc);
        jtfDtVenc.setBounds(10, 200, 90, 20);

        try {
            jtfDtPag.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jtfDtPag.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jtfDtPag.setName("jtfDtPag"); // NOI18N
        jpPrincNovo.add(jtfDtPag);
        jtfDtPag.setBounds(110, 200, 80, 20);

        jtfValorPago.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jtfValorPago.setText("0,00");
        jtfValorPago.setName("jtfValorPago"); // NOI18N
        jpPrincNovo.add(jtfValorPago);
        jtfValorPago.setBounds(440, 200, 130, 20);

        jLabel8.setText("Plano de Contas");
        jLabel8.setName("jLabel8"); // NOI18N
        jpPrincNovo.add(jLabel8);
        jLabel8.setBounds(10, 230, 110, 14);

        jtfPlanoCod.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jtfPlanoCod.setName("jtfPlanoCod"); // NOI18N
        jpPrincNovo.add(jtfPlanoCod);
        jtfPlanoCod.setBounds(10, 250, 100, 20);

        jtfPlanoDesc.setEditable(false);
        jtfPlanoDesc.setName("jtfPlanoDesc"); // NOI18N
        jpPrincNovo.add(jtfPlanoDesc);
        jtfPlanoDesc.setBounds(110, 250, 400, 20);

        jbBuscar1.setFont(new java.awt.Font("Dialog", 0, 10));
        jbBuscar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbBuscar1.setText("Buscar");
        jbBuscar1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbBuscar1.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jbBuscar1.setName("jbBuscar1"); // NOI18N
        jbBuscar1.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbBuscar1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbBuscar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscar1ActionPerformed(evt);
            }
        });
        jpPrincNovo.add(jbBuscar1);
        jbBuscar1.setBounds(520, 280, 50, 40);

        jtfCaixa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Caixa Geral" }));
        jtfCaixa.setName("jtfCaixa"); // NOI18N
        jpPrincNovo.add(jtfCaixa);
        jtfCaixa.setBounds(180, 90, 230, 20);

        jLabel9.setText("Caixa");
        jLabel9.setName("jLabel9"); // NOI18N
        jpPrincNovo.add(jLabel9);
        jLabel9.setBounds(180, 70, 110, 14);

        jtfValorBruto.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jtfValorBruto.setText("0,00");
        jtfValorBruto.setName("jtfValorBruto"); // NOI18N
        jtfValorBruto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtfValorBrutoFocusLost(evt);
            }
        });
        jpPrincNovo.add(jtfValorBruto);
        jtfValorBruto.setBounds(200, 200, 110, 20);

        jLabel10.setText("Valor Título");
        jLabel10.setName("jLabel10"); // NOI18N
        jpPrincNovo.add(jLabel10);
        jLabel10.setBounds(200, 180, 90, 14);

        jtfValorJuro.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jtfValorJuro.setText("0,00");
        jtfValorJuro.setName("jtfValorJuro"); // NOI18N
        jtfValorJuro.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jtfValorJuroFocusLost(evt);
            }
        });
        jpPrincNovo.add(jtfValorJuro);
        jtfValorJuro.setBounds(320, 200, 110, 20);

        jLabel11.setText("Juros");
        jLabel11.setName("jLabel11"); // NOI18N
        jpPrincNovo.add(jLabel11);
        jLabel11.setBounds(320, 180, 90, 14);

        jtfCentroCod.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jtfCentroCod.setName("jtfCentroCod"); // NOI18N
        jpPrincNovo.add(jtfCentroCod);
        jtfCentroCod.setBounds(10, 300, 100, 20);

        jtfCentroDesc.setEditable(false);
        jtfCentroDesc.setName("jtfCentroDesc"); // NOI18N
        jpPrincNovo.add(jtfCentroDesc);
        jtfCentroDesc.setBounds(110, 300, 400, 20);

        jLabel12.setText("Centro de Custos");
        jLabel12.setName("jLabel12"); // NOI18N
        jpPrincNovo.add(jLabel12);
        jLabel12.setBounds(10, 280, 120, 14);

        jbBuscar2.setFont(new java.awt.Font("Dialog", 0, 10));
        jbBuscar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbBuscar2.setText("Buscar");
        jbBuscar2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbBuscar2.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jbBuscar2.setName("jbBuscar2"); // NOI18N
        jbBuscar2.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbBuscar2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbBuscar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscar2ActionPerformed(evt);
            }
        });
        jpPrincNovo.add(jbBuscar2);
        jbBuscar2.setBounds(480, 10, 50, 40);

        jbBuscar3.setFont(new java.awt.Font("Dialog", 0, 10));
        jbBuscar3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbBuscar3.setText("Buscar");
        jbBuscar3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbBuscar3.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jbBuscar3.setName("jbBuscar3"); // NOI18N
        jbBuscar3.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbBuscar3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbBuscar3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscar3ActionPerformed(evt);
            }
        });
        jpPrincNovo.add(jbBuscar3);
        jbBuscar3.setBounds(520, 230, 50, 40);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Ação"));
        jPanel1.setName("jPanel1"); // NOI18N

        GrupoAcao.add(jtfAcaoPagar);
        jtfAcaoPagar.setSelected(true);
        jtfAcaoPagar.setText("Pagar");
        jtfAcaoPagar.setName("jtfAcaoPagar"); // NOI18N

        GrupoAcao.add(jtfAcaoProv);
        jtfAcaoProv.setText("Provisionar");
        jtfAcaoProv.setName("jtfAcaoProv"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfAcaoPagar)
                    .addComponent(jtfAcaoProv))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtfAcaoPagar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jtfAcaoProv)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpPrincNovo.add(jPanel1);
        jPanel1.setBounds(10, 440, 120, 90);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Rateio"));
        jPanel2.setName("jPanel2"); // NOI18N

        GrupoRateio.add(jrAuto);
        jrAuto.setSelected(true);
        jrAuto.setText("Automático");
        jrAuto.setName("jrAuto"); // NOI18N
        jrAuto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jrAutoMouseClicked(evt);
            }
        });

        GrupoRateio.add(jrManual);
        jrManual.setText("Manual");
        jrManual.setName("jrManual"); // NOI18N
        jrManual.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jrManualMouseClicked(evt);
            }
        });

        jtVlManual.setEditable(false);
        jtVlManual.setText("0,00");
        jtVlManual.setName("jtVlManual"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jtVlManual)
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jrAuto)
                            .addComponent(jrManual))
                        .addGap(5, 5, 5))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jrAuto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jrManual)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jtVlManual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpPrincNovo.add(jPanel2);
        jPanel2.setBounds(10, 330, 120, 110);

        jbNovo.setText("Novo");
        jbNovo.setEnabled(false);
        jbNovo.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbNovo.setName("jbNovo"); // NOI18N
        jbNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNovoActionPerformed(evt);
            }
        });
        jpPrincNovo.add(jbNovo);
        jbNovo.setBounds(340, 520, 70, 23);

        jbCancelar.setText("Cancelar");
        jbCancelar.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbCancelar.setName("jbCancelar"); // NOI18N
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });
        jpPrincNovo.add(jbCancelar);
        jbCancelar.setBounds(500, 520, 70, 23);

        jbSalvar.setText("Salvar");
        jbSalvar.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbSalvar.setMaximumSize(new java.awt.Dimension(51, 23));
        jbSalvar.setMinimumSize(new java.awt.Dimension(51, 23));
        jbSalvar.setName("jbSalvar"); // NOI18N
        jbSalvar.setPreferredSize(new java.awt.Dimension(51, 23));
        jbSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalvarActionPerformed(evt);
            }
        });
        jpPrincNovo.add(jbSalvar);
        jbSalvar.setBounds(420, 520, 70, 23);

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtPgto.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Ação", "Código", "Centro de Custo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtPgto.setName("jtPgto"); // NOI18N
        jScrollPane1.setViewportView(jtPgto);
        jtPgto.getColumnModel().getColumn(2).setPreferredWidth(300);
        jtPgto.getColumnModel().getColumn(2).setMaxWidth(300);

        jpPrincNovo.add(jScrollPane1);
        jScrollPane1.setBounds(140, 370, 430, 140);

        jbRemover.setText("Remover");
        jbRemover.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbRemover.setName("jbRemover"); // NOI18N
        jbRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRemoverActionPerformed(evt);
            }
        });
        jpPrincNovo.add(jbRemover);
        jbRemover.setBounds(220, 340, 70, 23);

        jbInserir.setText("Inserir");
        jbInserir.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbInserir.setName("jbInserir"); // NOI18N
        jbInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbInserirActionPerformed(evt);
            }
        });
        jpPrincNovo.add(jbInserir);
        jbInserir.setBounds(140, 340, 70, 23);

        jLabel13.setText("Parcela");
        jLabel13.setName("jLabel13"); // NOI18N
        jpPrincNovo.add(jLabel13);
        jLabel13.setBounds(510, 70, 60, 14);

        jtfParcela.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jtfParcela.setText("0");
        jtfParcela.setName("jtfParcela"); // NOI18N
        jpPrincNovo.add(jtfParcela);
        jtfParcela.setBounds(510, 90, 60, 20);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPrincNovo, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPrincNovo, javax.swing.GroupLayout.DEFAULT_SIZE, 557, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbBuscar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscar2ActionPerformed
        buscaVer.setTipo("Fornecedor");
        buscaVer bv = new buscaVer(null,true);
        bv.setLocation((index.tela.width-bv.getWidth())/2, (index.tela.height-bv.getHeight())/2);
        bv.setVisible(true);
        if(buscaVer.isConfirmaBusca()){
            jtfFornecedor.setText(index.LRpessoa.get(1).toString());
        }
    }//GEN-LAST:event_jbBuscar2ActionPerformed

    private void jbNovoFornActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNovoFornActionPerformed
        cadFornecedorRapido cfr = new cadFornecedorRapido(null,true);
        cfr.setLocation((index.tela.width-cfr.getWidth())/2, (index.tela.height-cfr.getHeight())/2);
        cfr.setVisible(true);
        if(cfr.finaliza==true){
            jtfFornecedor.setText(index.LRpessoa.get(1).toString());
        }
    }//GEN-LAST:event_jbNovoFornActionPerformed

    private void jbBuscar3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscar3ActionPerformed
        buscaPlanoContas bv = new buscaPlanoContas(null,true);
        bv.setLocation((index.tela.width-bv.getWidth())/2, (index.tela.height-bv.getHeight())/2);
        bv.setVisible(true);
        if(buscaPlanoContas.isConfirmaContas()){
            jtfPlanoCod.setEditable(false);
            jtfPlanoCod.setText(index.LRcontas.get(0).toString());
            jtfPlanoDesc.setText(index.LRcontas.get(1).toString());
        }
        
    }//GEN-LAST:event_jbBuscar3ActionPerformed

    private void jbBuscar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscar1ActionPerformed
        buscaCentroCusto bv = new buscaCentroCusto(null,true);
        bv.setLocation((index.tela.width-bv.getWidth())/2, (index.tela.height-bv.getHeight())/2);
        bv.setVisible(true);
        if(buscaCentroCusto.isConfirmaCentro()){
            jtfCentroCod.setEditable(false);
            jtfCentroCod.setText(index.LRcentro.get(0).toString());
            jtfCentroDesc.setText(index.LRcentro.get(1).toString());
        }
    }//GEN-LAST:event_jbBuscar1ActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        jtfFornecedor.setText(index.LRpessoa.get(1).toString());
        carregaCaixa();
    }//GEN-LAST:event_formWindowOpened

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed

    }//GEN-LAST:event_formWindowClosed

    private void jbInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbInserirActionPerformed
        if(!jtfCentroDesc.getText().equals("")){
            if(!jtfValorPago.getText().equals("")){
                javax.swing.table.DefaultTableModel jtp = (javax.swing.table.DefaultTableModel) jtPgto.getModel();
                jtp.addRow(new Object[]{(jrAuto.isSelected())?jrAuto.getText():jtVlManual.getText(),jtfCentroCod.getText(),jtfCentroDesc.getText()});
            }else{
                JOptionPane.showMessageDialog(null, "Valor Pago é um campo Obrigatório.","Informação do Sistema",JOptionPane.ERROR_MESSAGE);
            }
        }else{
            JOptionPane.showMessageDialog(null, "Centro de Custo é um campo Obrigatório.","Informação do Sistema",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jbInserirActionPerformed

    private void jbRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRemoverActionPerformed
        javax.swing.table.DefaultTableModel jtb = (javax.swing.table.DefaultTableModel) jtPgto.getModel();
        jtb.removeRow(jtPgto.getSelectedRow());
    }//GEN-LAST:event_jbRemoverActionPerformed

    private void jrManualMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jrManualMouseClicked
        jtVlManual.setEditable(true);
    }//GEN-LAST:event_jrManualMouseClicked

    private void jrAutoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jrAutoMouseClicked
         jtVlManual.setEditable(false);
    }//GEN-LAST:event_jrAutoMouseClicked

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
        dispose();
    }//GEN-LAST:event_jbCancelarActionPerformed

    private void jbSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalvarActionPerformed
        try {
            if(!index.LRpessoa.get(0).equals("")){
                if(jtPgto.getRowCount()>0){
                    if(jtfCaixa.getSelectedIndex()!=0){
                        if(!jtfPlanoDesc.getText().equals("")){
                            if(!jtfDtVenc.getText().equals("  /  /    ")){
                                double vlr=0.00;
                                double vlb=0.00;
                                boolean cadastra=false;
                                String status;
                                if(jtfAcaoPagar.isSelected()){
                                    status = "Pago";
                                }else{
                                    status = "A Pagar";
                                }
                                if(jrManual.isSelected()){
                                    for(int i=0; i<jtPgto.getRowCount();i++){
                                        vlr=index.ftes.parse(jtPgto.getValueAt(i, 0).toString()).doubleValue();
                                    }
                                }else{vlr=index.ftes.parse(jtfValorPago.getText()).doubleValue();}
                                if(vlr==index.ftes.parse(jtfValorPago.getText()).doubleValue()){
                                    for(int i=0; i<jtPgto.getRowCount();i++){
                                        if(jtfAcaoPagar.isSelected()){
                                            if(jrAuto.isSelected()){
                                                if(jtPgto.getRowCount()>1){
                                                    vlr = index.ftes.parse(jtfValorPago.getText()).doubleValue()/jtPgto.getRowCount();
                                                    vlb = index.ftes.parse(jtfValorBruto.getText()).doubleValue()/jtPgto.getRowCount();
                                                }else{ vlr = index.ftes.parse(jtfValorPago.getText()).doubleValue(); vlb = index.ftes.parse(jtfValorBruto.getText()).doubleValue(); }
                                            }else{ vlr=index.ftes.parse(jtPgto.getValueAt(i, 0).toString()).doubleValue(); vlb = index.ftes.parse(jtfValorBruto.getText()).doubleValue(); }
                                            if(!jtfDtPag.getText().equals("  /  /    ")){
                                                cadastra=true;
                                            }else{
                                                cadastra=false;
                                                JOptionPane.showMessageDialog(null, "Campo Data de Pgto é Obrigatório.", "Informação do Sistema", JOptionPane.ERROR_MESSAGE);
                                            }
                                        }else{
                                            vlr=0.00;
                                            cadastra=true;
                                            if(jrAuto.isSelected()){
                                                if(jtPgto.getRowCount()>1){
                                                    vlb = index.ftes.parse(jtfValorBruto.getText()).doubleValue()/jtPgto.getRowCount();
                                                }else{ vlb = index.ftes.parse(jtfValorBruto.getText()).doubleValue(); }
                                            }else{ vlb=index.ftes.parse(jtPgto.getValueAt(i, 0).toString()).doubleValue(); }
                                        }
                                        if(cadastra){
                                            String dtpgto = (!jtfDtPag.getText().equals("  /  /    "))?"\""+index.dtcv.converte("US", jtfDtPag.getText())+"\"":"null";
                                            String user = (!jtfAcaoProv.isSelected())?index.usuario[0]:"null";
                                            String dtlanc = (jtfAcaoPagar.isSelected())?"now()":"null";
                                            String vljuro = (jtfAcaoProv.isSelected()&&jtfValorJuro.getText().equals("0,00"))?"null":"\""+index.ftes.parse(jtfValorJuro.getText()).doubleValue()+"\"";
                                            conexao.Inserir("insert into fin_contas_mov_p(cod_emp,cod_plano_contas,cod_centro_custos,cod_caixa,cod_usuario,cod_pessoa,desc_titulo,nr_documento,parcela,descricao,dt_emissao,dt_lancamento,dt_pagamento,dt_vencimento,valor_bruto,juros,valor,status) " +
                                                " values(" + index.cod_emp + "," + jtfPlanoCod.getText() + ","+jtPgto.getValueAt(i, 1)+"," + LRcaixa.get(jtfCaixa.getSelectedIndex()) + ","+user+"," + index.LRpessoa.get(0) + ",\"" + jtfTipo.getSelectedItem() + "\"," + jtfNrDoc.getText() + "," + jtfParcela.getText() + ",\"" + jtfHistorico.getText() + "\",now(),"+dtlanc+"," +dtpgto+ ",\""+index.dtcv.converte("US", jtfDtVenc.getText())+"\",\""+vlb+"\","+vljuro+",\""+vlr+"\",\""+status+"\")");
                                        }
                                    }
                                    if(cadastra){
                                        carregaBotao();
                                        finaliza=true;
                                    }
                                }else{
                                    JOptionPane.showMessageDialog(null, "Somatório das Contas não conferem.", "Informação do Sistema", JOptionPane.ERROR_MESSAGE);
                                }
                            }else{
                                JOptionPane.showMessageDialog(null, "Campo Plano de Contas é Obrigatório.", "Informação do Sistema", JOptionPane.ERROR_MESSAGE);
                            }
                        }else{
                            JOptionPane.showMessageDialog(null, "Campo Data de Venc. é Obrigatório.", "Informação do Sistema", JOptionPane.ERROR_MESSAGE);
                        }
                    }else{
                        JOptionPane.showMessageDialog(null, "Campo Caixa é Obrigatório.", "Informação do Sistema", JOptionPane.ERROR_MESSAGE);
                    }
                }else{
                    JOptionPane.showMessageDialog(null, "Favor Inserir o(s) Centro(s).", "Informação do Sistema", JOptionPane.ERROR_MESSAGE);
                }
            }else{
                JOptionPane.showMessageDialog(null, "Campo Fornecedor é Obrigatório.", "Informação do Sistema", JOptionPane.ERROR_MESSAGE);
            }
        } catch (ParseException ex) {
            verErros.setErro(ex.getMessage());
        }
    }//GEN-LAST:event_jbSalvarActionPerformed

    private void jbNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNovoActionPerformed
        carregaBotao();
        jtfPlanoCod.setEditable(!jtfPlanoCod.isEditable());
        jtfCentroCod.setEditable(!jtfCentroCod.isEditable());
        limpaCampos();
        javax.swing.table.DefaultTableModel jtp = (javax.swing.table.DefaultTableModel) jtPgto.getModel();
        for (int x = jtPgto.getRowCount() - 1; x >= 0; --x) {
            jtp.removeRow(x);
        }

    }//GEN-LAST:event_jbNovoActionPerformed

    private void jtfValorBrutoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfValorBrutoFocusLost
        jtfValorPago.setText(jtfValorBruto.getText());
    }//GEN-LAST:event_jtfValorBrutoFocusLost

    private void jtfValorJuroFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfValorJuroFocusLost
        try {
            double valor = index.ftes.parse(jtfValorBruto.getText()).doubleValue() + index.ftes.parse(jtfValorJuro.getText()).doubleValue();
            jtfValorPago.setText(index.ftbr.format(valor));
        } catch (ParseException ex) {
            verErros.setErro(ex.getMessage());
        }
    }//GEN-LAST:event_jtfValorJuroFocusLost
    private void carregaBotao(){
        jbNovo.setEnabled(!jbNovo.isEnabled());
        jbSalvar.setEnabled(!jbSalvar.isEnabled());
        jbInserir.setEnabled(!jbInserir.isEnabled());
        jbRemover.setEnabled(!jbRemover.isEnabled());
        jtfNrDoc.setEditable(!jtfNrDoc.isEditable());
        jtfParcela.setEditable(!jtfParcela.isEditable());
        jtfHistorico.setEditable(!jtfHistorico.isEditable());
        jtfDtVenc.setEditable(!jtfDtVenc.isEditable());
        jtfDtPag.setEditable(!jtfDtPag.isEditable());
        jtfValorBruto.setEditable(!jtfValorBruto.isEditable());
        jtfValorJuro.setEditable(!jtfValorJuro.isEditable());
        jtfValorPago.setEditable(!jtfValorPago.isEditable());
    }
    private void limpaCampos(){
        jtfNrDoc.setText("0");
        jtfParcela.setText("0");
        jtfHistorico.setText("");
        jtfDtVenc.setText("  /  /    ");
        jtfDtPag.setText("  /  /    ");
        jtfValorBruto.setText("0,00");
        jtfValorJuro.setText("0,00");
        jtfValorPago.setText("0,00");
        jtfPlanoCod.setText("");jtfPlanoDesc.setText("");
        jtfCentroCod.setText("");jtfCentroDesc.setText("");
        jtVlManual.setText("0,00");
    }
    private void carregaCaixa(){
        jtfCaixa.removeAllItems();
        try {            
            conexao.Query("select fc.codigo,fc.descricao from fin_caixa fc " +
                    " inner join usuarios_caixas u on u.cod_caixa=fc.codigo and u.cod_emp=fc.cod_emp " +
                    " where fc.cod_emp="+index.cod_emp+" and u.cod_usuario="+index.usuario[0]+" order by descricao");
            LRcaixa.add(0);
            jtfCaixa.addItem("Selecione um Caixas");
            while(conexao.rs.next()){
                LRcaixa.add(conexao.rs.getString("codigo"));
                jtfCaixa.addItem(conexao.rs.getString("descricao"));
            }
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup GrupoAcao;
    private javax.swing.ButtonGroup GrupoRateio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbBuscar1;
    private javax.swing.JButton jbBuscar2;
    private javax.swing.JButton jbBuscar3;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbInserir;
    private javax.swing.JButton jbNovo;
    private javax.swing.JButton jbNovoForn;
    private javax.swing.JButton jbRemover;
    private javax.swing.JButton jbSalvar;
    private javax.swing.JPanel jpPrincNovo;
    private javax.swing.JRadioButton jrAuto;
    private javax.swing.JRadioButton jrManual;
    private javax.swing.JTable jtPgto;
    private javax.swing.JTextField jtVlManual;
    private javax.swing.JRadioButton jtfAcaoPagar;
    private javax.swing.JRadioButton jtfAcaoProv;
    private javax.swing.JComboBox jtfCaixa;
    private javax.swing.JTextField jtfCentroCod;
    private javax.swing.JTextField jtfCentroDesc;
    private javax.swing.JFormattedTextField jtfDtPag;
    private javax.swing.JFormattedTextField jtfDtVenc;
    private javax.swing.JTextField jtfFornecedor;
    private javax.swing.JTextField jtfHistorico;
    private javax.swing.JTextField jtfNrDoc;
    private javax.swing.JTextField jtfParcela;
    private javax.swing.JTextField jtfPlanoCod;
    private javax.swing.JTextField jtfPlanoDesc;
    private javax.swing.JComboBox jtfTipo;
    private javax.swing.JTextField jtfValorBruto;
    private javax.swing.JTextField jtfValorJuro;
    private javax.swing.JTextField jtfValorPago;
    // End of variables declaration//GEN-END:variables

}
